package leetcode1;

public class Day12 {

    public static void main(String[] args) {
        int[] nums = {2,0,1,1,2,1,0,0,0};
        //canJump(nums);
    }
    public boolean canJump(int[] nums) {
        int n = nums.length;
        int maxpos=0,left=0,right=0;
        while(left <= right) {
            if(maxpos>=n-1) return true;
            for(int i=left;i<=right;i++) {
                maxpos=Math.max(maxpos,nums[i]+i);
            }
            left=right+1;
            right=maxpos;
        }
        return false;
    }
}
